/*
 * @Author: duanguang
 * @Date: 2020-08-02 23:34:18
 * @LastEditTime: 2021-10-27 23:03:56
 * @LastEditors: duanguang
 * @Description: 
 * @FilePath: /legions-server/app/io/controller/author.ts
 * 「扫去窗上的尘埃，才可以看到窗外的美景。」
 */
import { Controller } from 'egg';
interface IPrams {
    token: string;
    authApi: string;
}
interface IResponse {
    data: Buffer;
    res: {
        status: number;
    };
}
export default class AuthorController extends Controller {
  public async index() {
      if (this.ctx.args && Array.isArray(this.ctx.args)) {
        const Authorization = this.ctx.args[0] as IPrams;
        const opts = {
            headers: { Cookie: Authorization.token },
            dataType: 'application/json',
            timeout: 40000,
        };
        const result: IResponse = (await this.ctx.curl<IResponse>(Authorization.authApi, opts)) as any;
        const socketResult = {
            userEntity: JSON.stringify(result.data.toString()),
            status: result.res.status,
        };
        /* console.log(file); */
       /*  fs.writeFileSync(file, 'content'); */
        await this.ctx.socket.emit('message', socketResult);
      }
  }
}
